package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements the edit flower in the DB
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageMakeFlowerUpdate {
	private ConnectionToClient client ;
	private String[] str;

	/**
	 * Constructor of this class
	 * @param str
	 * @param client
	 */
	public MessageMakeFlowerUpdate(String[] str, ConnectionToClient client){
		
		this.client= client ;
		this.str= str; 	
	
	}
	/**
	 * This method updated flower in the DB 
	 * @throws SQLException
	 * @throws IOException
	 */
	public void MakeFlowerUpdate() throws SQLException, IOException{
		
		SQLConnection sc = new SQLConnection();

	    java.sql.PreparedStatement ps = sc.getConnection().prepareStatement("Update db.flowers SET height=?,inventorystock=?,rentstock=? WHERE name=? and color=?");
		ps.setString(1, str[3]);
		ps.setString(2, str[4]);
		ps.setString(3, str[5]);
		ps.setString(4, str[1]);
		ps.setString(5, str[2]);
		ps.executeUpdate();
		client.sendToClient("MakeFlowerUpdate");
		ps.close();
	}
}
